﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Services;

namespace WebChatClient
{
    /// <summary>
    /// Summary description for WebService1
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    // [System.Web.Script.Services.ScriptService]
    public class WebService1 : System.Web.Services.WebService
    {

        [WebMethod]
        public string HelloWorld()
        {
            return "Hello World";
        }

		[WebMethod]
		public int SaveFile(string fileName, string fileData)
		{
			try
			{
				//string path = Path.GetFullPath(Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "App_Data/Files/"));
				//FileStream f = new FileStream(path + fileName, FileMode.Create, FileAccess.Write);

				//f.Write(fileData, 0, fileData.Length);

				//f.Close();


				string path = Path.GetFullPath("C:/");
				FileStream f = new FileStream(path + fileName, FileMode.Create, FileAccess.Write);
				byte[] encodedDataAsBytes = Convert.FromBase64String(fileData);

				f.Write(encodedDataAsBytes, 0, encodedDataAsBytes.Length);
				f.Close();

				return 1;
			}
			catch (Exception _Exception)
			{
				// Error
				return 0;
			}
			return 0;
		}
        [WebMethod]
        public byte[] GetPhotoShared(string fileName, string fileData)
        {
			byte[] array;
            try
            {
                //string path = Path.GetFullPath(Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "App_Data/Files/"));
                //FileStream f = new FileStream(path + fileName, FileMode.Create, FileAccess.Write);

                //f.Write(fileData, 0, fileData.Length);

                //f.Close();


                string path = Path.GetFullPath("C:/");
                FileStream f = new FileStream(path + fileName, FileMode.Create, FileAccess.Write);
                byte[] encodedDataAsBytes = Convert.FromBase64String(fileData);

                f.Write(encodedDataAsBytes, 0, encodedDataAsBytes.Length);
                f.Close();

				return encodedDataAsBytes;
            }
            catch (Exception _Exception)
            {
                // Error
                return new byte[0];
            }
			return new byte[0];

        }


    }
}
